package com.neusoft.elm01.controller;

import com.neusoft.elm01.entity.CommonResult;
import com.neusoft.elm01.entity.Dept;
import com.neusoft.elm01.service.DeptService;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/dc")
public class DeptController {
    @Autowired
    DeptService service;
    @GetMapping("/q/all")
    public CommonResult findAll(){

        return service.findAll();
    }
    @PutMapping("/add")
    public CommonResult add(@RequestBody Dept dept){
        dept.setDeptno(null);
        return service.add(dept);
    }
    @DeleteMapping("/delete/{depno}")
    public CommonResult delete(@PathVariable int depno){
        return service.deleteById(depno);
    }
    @PostMapping("/mod")
    public CommonResult modDept(@RequestBody Dept dept){
        return service.update(dept);
    }
    @GetMapping("/q/byid/{id}")
    public CommonResult findById(@PathVariable int id){
        return service.findById(id);

    }
}
